<?php
/**
 * Created by PhpStorm.
 * User: ycp
 * Date: 2019/5/23
 * Time: 22:23
 */

namespace app\api\controller;


class Search extends ApiCommon
{
    protected $activityTable = 'lite_activity';
    protected $countryTable = 'sys_country';
    protected $provinceTable = 'sys_province';
    protected $cityTable = 'sys_city';


    public function __construct()
    {
        parent::__construct();
    }

    //
    public function index()
    {
        $cate = config('data.activity_type');
        $cateData = [];
        foreach ($cate as $k => $datum){
            $cateData[$k]['title'] = $datum['name'];
            $cateData[$k]['value'] = $k;
        }
        $city = db($this->provinceTable)->where(['country_code' => 1])->field('code as value, name as title')->select();
//        $country = db($this->countryTable)->where('code','<>',1)->field('code as value, name as title')->limit(100)->select();
        $countryStr = '全部,美国,加拿大,英国,德国,法国,澳大利亚,意大利,韩国,日本,墨西哥,秘鲁,古巴,智利,巴西,阿根廷,爱尔兰,希腊,挪威,波兰,芬兰,西班牙,葡萄牙,丹麦,比利时,荷兰,瑞典,瑞士,奥地利,俄罗斯,乌克兰,新西兰,马来西亚,泰国,菲律宾,柬埔寨,缅甸,越南,印度,老挝,尼泊尔,土耳其,也门,阿富汗,巴基斯坦,以色列,埃及,南非,肯尼亚,其他';
        $country = explode(',', $countryStr);
        foreach ($country as $key => $value){
            $countryRes[$key]['title'] = $value;
            $countryRes[$key]['value'] = $value;
        }
        $hotStr = '全部,北京,上海,深圳,西安,重庆';
        $hot = explode(',', $hotStr);
        foreach ($hot as $key => $value){
            $hotRes[$key]['title'] = $value;
            $hotRes[$key]['value'] = $value;
        }

        array_unshift($city, [
            'title' => '全部',
            'value' => '-1',
        ]);

        $cityData = [
            [
                'title' => '热门',
                'value' => '1',
                'itemList' => $hotRes
            ],
            [
                'title' => '国内',
                'value' => '2',
                'itemList' => $city
            ],
            [
                'title' => '海外',
                'value' => '3',
                'itemList' => $countryRes
            ]
        ];


        $yearTime = ['-2', '-1', '0', '+1'];
        $dateData = $monthData = [];
        for($i = 1; $i < 13; $i++){
            $monthData[$i-1]['title'] = $i .'月';
            $monthData[$i-1]['value'] = $i;
        }

        array_unshift($monthData, [
            'title' => '全部',
            'value' => '-1',
        ]);

        foreach ($yearTime as $key => $value){
            $dateData[$key]= [
                'title' => date("Y", strtotime($value . " year")),
                'value' => date("Y", strtotime($value . " year")),
                'itemList' => $monthData
            ];
        }


        array_unshift($cityData, [
            'title' => '全部',
            'value' => '-1',
            'itemList' => []
        ]);
         array_unshift($cateData, [
            'title' => '全部',
            'value' => '-1',
            'itemList' => []
        ]);
         array_unshift($dateData, [
            'title' => '全部',
            'value' => '-1',
            'itemList' => []
        ]);

        $res['cateData'] = $cateData;
        $res['cityData'] = $cityData;
        $res['dateData'] = $dateData;
        $this->success('成功！', $res);

    }

    public function search()
    {

    }
}